package com.eee.xiang.market.utils;

import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;

public class EmailUtil {

    private static final String EMAIL_HOST = "smtp.ym.163.com";
    private static final String USER_NAME = "zhangdan@biku8.com";
    private static final String PASSWORD = "biku821013";
    private static final String FROM_MAIL = "zhangdan@biku8.com";
    private static final String PERSONAL = "珠海比酷网络科技有限公司";
    private static final String SSL_FACTORY ="javax.net.ssl.SSLSocketFactory" ;
    public static final String HTML_ACCOUNT_TEMPLATE ="<body><h1 style='margin-left:17px;'>%s结算对账单</h1>" +
            "<table>" +
            "<tr><td>合作伙伴名称:</td><td style='padding:0 0 0 48px;'>%s</td></tr>" +
            "<tr><td>结算单号:</td><td style='padding:0 0 0 48px;'>%s</td></tr>" +
            "<tr><td>结算日期:</td><td style='padding:0 0 0 48px;'>%s</td></tr>" +
            "<tr><td>结算业务名称:</td><td style='padding:0 0 0 48px;'>%s</td></tr>" +
            "<tr><td>制表日期:</td><td style='padding:0 0 0 48px;'>%s</td></tr>" +
            "</table>" +
            "<table style='text-align:center;width:385px;margin-top:12px' border='1'><tr><th>结算日期</th><th>分成金额</th></tr>" +
            "<tr><td>%s</td><td>%s</td></tr>" +
            "</table>" +
            "<table style='margin-top:12px'>" +
            "<tr><td>发票客户名称:</td><td style='padding:0 0 0 48px;'>%s</td></tr>" +
            "</table>" +
            "<div style='font-weight:bold;padding: 10 0 0 320px;'>" +
            "<span>回执栏</span>" +
            "</div>" +
            "<div>" +
            "<p>数据确认:</p>" +
            "<p>公司（签字）</p>" +
            "<p style='margin-top:12px'>公司（盖章）</p> " +
            "<p>日期：</p>" +
            "</div></body>";

    private  static JavaMailSenderImpl createMailSender() {
        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        sender.setHost(EMAIL_HOST);
        sender.setPort(25);
        sender.setUsername(USER_NAME);
        sender.setPassword(PASSWORD);
        sender.setDefaultEncoding("Utf-8");
        Properties p = new Properties();
        p.setProperty("mail.smtp.timeout", "25000");
        p.setProperty("mail.smtp.auth", "true");
        p.setProperty("mail.smtp.socketFactory.class",SSL_FACTORY);
        p.put("mail.smtp.port", "465");
        p.put("mail.smtp.socketFactory.port", "465");
        sender.setJavaMailProperties(p);
        return sender;
    }

    public static String makeEmailHtml4Account(String titleCompany,
                                               String partnerName,
                                               String accountId,
                                               String accountDate,
                                               String bussiness,
                                               String makeDate,
                                               String accountDay,
                                               String divideMoney,
                                               String companyName
    ){
        return String.format(HTML_ACCOUNT_TEMPLATE,titleCompany,partnerName,accountId,accountDate,bussiness,makeDate,accountDay,divideMoney,PERSONAL);
    }

}
